
package com.mashibing.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Classname RabbitMQConnectionUtil
 * @Description 创建mq工具类
 * @Date 2022/4/20 23:50
 * @Created by 666
 */
public class RabbitMQConnectionUtil {
    public static final String RABBITMQ_HOST = "192.168.0.81";
    public static final int RABBITMQ_PORT = 5672;
    public static final String RABBITMQ_USERNAME = "guest";
    public static final String RABBITMQ_PASSWORD = "guest";
    public static final String RABBITMQ_VIRTUAL_HOST = "/";

    public static Connection getConnection() throws Exception {
        //1、创建工厂类
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //2、设置rabbitMQ的参数
        connectionFactory.setHost(RABBITMQ_HOST);
        connectionFactory.setPort(RABBITMQ_PORT);
        connectionFactory.setUsername(RABBITMQ_USERNAME);
        connectionFactory.setPassword(RABBITMQ_PASSWORD);
        connectionFactory.setVirtualHost(RABBITMQ_VIRTUAL_HOST);
        //3.返回链接对象
        Connection connection = connectionFactory.newConnection();
        return connection;
    }
}
